package com.lengxf.milo.executor;

import com.lengxf.milo.callBack.DataValueListenerCallBack;
import com.lengxf.milo.callBack.DefaultDataValueListenerCallBack;
import com.lengxf.milo.listener.ReSubscriptionListener;
import com.lengxf.milo.node.NodeIdBuilder;
import org.eclipse.milo.opcua.sdk.client.api.UaClient;
import org.eclipse.milo.opcua.stack.core.UaException;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;

import java.util.List;
import java.util.stream.Collectors;

public class SubscriptionExecutor {

    public static void subscribe(UaClient client, List<String> identifierList, DataValueListenerCallBack callBack) throws UaException {
        List<NodeId> nodeIdList = identifierList.stream().map(NodeIdBuilder::build).collect(Collectors.toList());
        ReSubscriptionListener reSubscriptionListener = new ReSubscriptionListener(client, nodeIdList, callBack);
        client.getSubscriptionManager().addSubscriptionListener(reSubscriptionListener);
    }

    public static void subscribe(UaClient client, List<String> identifierList) throws UaException {
        subscribe(client, identifierList, new DefaultDataValueListenerCallBack());
    }

}
